/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package examples;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.text.StyleConstants;

/**
 *
 * @author Kelly Ruiz
 */
public class TestRadioButton extends JFrame {
    
    private JTextField campotexto;
    private JRadioButton cursiva;
    private JRadioButton negrita;
    private JRadioButton simple;
    private JRadioButton negritaCursiva;
    private ButtonGroup grupOpcion;    
    
    private Font fontSimple;
    private Font fontNegrita;
    private Font fontCursiva;
    private Font fontCursivaNegrita;
    
    public TestRadioButton(){
        
        //StyleConstants.Superscript(
        super("Prueba de RadioButton");
        setLayout(new FlowLayout());
        
        fontSimple = new Font("Serif", Font.PLAIN, 24);
        fontNegrita = new Font("Serif", Font.BOLD, 24);
        fontCursiva = new Font("Serif", Font.ITALIC, 24);
        fontCursivaNegrita = new Font("Serif", Font.PLAIN + Font.ITALIC, 24);
        
        
        campotexto = new JTextField("Aquí tenemos el texto que vamos a cambiar", 28);
        add(campotexto);
        
        
        
        negrita = new JRadioButton("Negrita", false);
        cursiva = new JRadioButton("Cursiva", false);
        //cursiva = new JRadioButton
        simple = new JRadioButton("Simple", true);
        negritaCursiva = new JRadioButton("Negrita/Cursiva", false);
        add(negrita);
        add(cursiva);
        add(simple);
        add(negritaCursiva);
        campotexto.setFont(fontSimple);
        
        grupOpcion = new ButtonGroup();
        grupOpcion.add(negrita);
        grupOpcion.add(cursiva);
        grupOpcion.add(simple);
        grupOpcion.add(negrita);
        
        ManejadorEventos driversEvent = new ManejadorEventos();
        cursiva.addItemListener(driversEvent);
        simple.addItemListener(driversEvent);
        negritaCursiva.addItemListener(driversEvent);
        negrita.addItemListener(driversEvent);
        
    }
    
    private class ManejadorEventos implements ItemListener
    {

       // @Override
        public void itemStateChanged(ItemEvent e) {
         //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            
            if (e.getSource() == negrita){
                if (negrita.isSelected()){
                     cursiva.setSelected(false);
                    simple.setSelected(false);
                    negritaCursiva.setSelected(false);
                    negrita.setSelected(true);
                   
                    campotexto.setFont(fontNegrita);
                }         
            }
            if (e.getSource() == cursiva){
                if (cursiva.isSelected()){
                    simple.setSelected(false);
                    negritaCursiva.setSelected(false);
                    negrita.setSelected(false);
                    cursiva.setSelected(true);
                    
                    campotexto.setFont(fontCursiva);
                }         
            }
            if (e.getSource() == simple){
                if (simple.isSelected()){
                    negritaCursiva.setSelected(false);
                    negrita.setSelected(false);
                    cursiva.setSelected(false);
                    simple.setSelected(true);
                    
                    campotexto.setFont(fontSimple);
                }         
            }
            if (e.getSource() == negritaCursiva){
                if (negritaCursiva.isSelected()){
                    negritaCursiva.setSelected(true);
                    negrita.setSelected(false);
                    cursiva.setSelected(false);
                    simple.setSelected(false);
                    campotexto.setFont(fontCursivaNegrita);
                }         
            }
            
        }
        
    }
}
